package net.melon.agency.pojo.dto.impl;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

import net.esj.auth.pojo.CoreAuthFunc;
import net.esj.background.support.BgMenu;

public class AgencyBgMenu implements BgMenu {
	
	private String id;
	private String parentId;
	private String ico;
	private String name;
	private String url;
	private Set<BgMenu> children;
	private boolean isMenu;
	private boolean isOpen = false;
	private int sort;
	
	public AgencyBgMenu(CoreAuthFunc func) {
		this.id = func.getId();
		this.ico = func.getIcon();
		if(func.getParent()!=null){
			this.parentId = func.getParent().getId();
		}
		this.name = func.getName();
		this.url = func.getUrl();
		this.isMenu = func.getIsMenu();
		this.children = new TreeSet<BgMenu>(new Comparator<BgMenu>() {

			@Override
			public int compare(BgMenu o1, BgMenu o2) {
				return ((AgencyBgMenu)o1).getSort()-((AgencyBgMenu)o2).getSort();
			}
		});
		this.sort = func.getSort();
//		for(CoreAuthFunc cf: func.getChildren()){
//			this.children.add(new AuthMenu(cf));
//		}
	}
	
	@Override
	public String getIco() {
		return ico;
	}

	@Override
	public boolean isMenu() {
		return isMenu;
	}

	@Override
	public boolean isOpen() {
		return isOpen;
	}

	@Override
	public Set<BgMenu> getChildMenus() {
		return children;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public String getUrl() {
		return url;
	}

	@Override
	public String getId() {
		return id;
	}

	@Override
	public String getParentId() {
		return parentId;
	}

	public int getSort() {
		return sort;
	}

	public void setSort(int sort) {
		this.sort = sort;
	}

}
